// TOWN SCRIPT
//    Town 0: Tovas' Lair

// This is the special encounter script for this town.
// The states INIT_STATE, EXIT_STATE, and START_STATE have
// meanings that are described in the documenation. States you write
// yourself should be numbered from 10-100.

begintownscript;

variables;

body;

beginstate INIT_STATE;
// Called upon entering

set_terrain(19,35,0);

set_flag(7,13,0); //Resets antler


if(get_flag(7,22) == 0) {
	reset_dialog();
	add_dialog_str(0,"You finally reach your destination - Tovas's lair. It is a formidable looking structure, both imposing and terrifying, and you balk at the thought of going inside. You have a quick look around this small courtyard for signs of Laurina, but see none.",0);
	add_dialog_str(1,"In fact, you see no signs of human life at all. The air is still; heavy with the scent of lilacs, and everything is silent, except for a gentle breeze stirring the nearby trees.",0);
	add_dialog_str(2,"It look like you have no choice but to press on into this cathedral of death.",0);
	run_dialog(1);
	set_flag(7,22,1);
}

set_name(8,"Garden Ghost");
set_name(10,"Library Ghost");

break;

beginstate EXIT_STATE;
// Always called when the town is left.
break;

beginstate START_STATE;
// Called every turn.
break;

beginstate 10; //SE Crypt door
	if(get_flag(7,1) == 0) {
		message_dialog("You open this door warily, fully expecting Tovas to leap out at you, fangs bared. Fortunately, this doesn't happen, although the true contents of the room are only slightly more comforting.","Half a dozen coffins, all closed, lie along the outer walls. Bracing yourself, you peer at one - the name plate, however, is blank. It looks like they haven't been used yet.");
		set_flag(7,1,1);
	}
break;

beginstate 11; //Library doors
	if(get_flag(7,2) == 0) {
		message_dialog("You throw open these grand, wooden doors, and peer into the darkened room. You can make out the tall, looming shapes of bookcases, and the air has the whiff of ink and musty paper.","This must be the library - no doubt a place Tovas spends much of his time. You dearly hope he isn't here at the moment...");
		set_flag(7,2,1);
	}
break;

beginstate 12; //Temple Door
	if(get_flag(7,3) == 0) {
		message_dialog("You enter this small-ish chapel. It is an altogether more sinister place than you imagined a room of worship could be. Because of the obvious lack of natural light, everything is bathed in a flickering orange glow, and the air is hung with smoke.","Also, there are no chairs, just a single prayer mat, where you assume Tovas kneels and prays. The idea of a beast as evil as Tovas praying is, however, completely alien to you.");
		set_flag(7,3,1);
	}
break;

beginstate 13; //Prayer Mat in Temple
	message_dialog("As you approach the mat, you get an over-whelming feeling of... of *something* unpleasant. It is a mix of heart-wrenching solitude, and guilt, and hatred, and fear, and more besides.","Needless to say, you don't hang around the mat long enough to experience the feeling for very long...");
	block_entry(1);
break;	

beginstate 14; //Main hall
	if(get_flag(7,4) == 0) {
		reset_dialog();
		add_dialog_str(0,"You open these next doors apprehensively - the decor has been getting more and more elaborate the more you explore, and it is only a matter of time until you find Tovas.",0);
		add_dialog_str(1,"And, as you look into this room, you fully expect to see him looming out at you - this is clearly a throne room, complete with elevated seat and all.",0);
		add_dialog_str(2,"However, the master of the house is not in here, and you have a brief look around. Despite the awe-inspiring architecture, everything has a fine layer of dust. Tovas must not spend much time in here.",0);
		run_dialog(1);
		set_flag(7,4,1);
	}
break;

beginstate 15; //Kitchen things
	if(get_flag(7,5) == 0) {
		message_dialog("You approach the cooking end of the dining hall. Everything here is dusty and unused - the oven and cauldron are empty, and the cooler box is bare. There has been no cooking here for some time.","Tovas must get the food he (or his 'guests') need elsewhere.");
		set_flag(7,5,1);
	}
break;

beginstate 16; //Dining Room doors
	if(get_flag(7,6) == 0) {
		message_dialog("You open these doors and find the Tower's dining room. The place was designed to be a grand hall, with tapestries and paintings to awe the guests. However, the room now is just cold and unwelcoming, in a very melancholy way.","There is just one place set now; a simple clay bowl at the head table. Since it cannot be for Tovas, this must be where Laurina eats.");
		set_flag(7,6,1);
	}
break;

beginstate 17; //Guestrooms
	if(get_flag(7,7) == 0) {
		message_dialog("You enter this room. It appears as though this part of the Tower was built to house visitors whilst they stayed here. Clearly this place wasn't always as remote as it is now.","Looking around, you see the rooms are very dusty. It's almost as if nobody has been in here for years.");
		set_flag(7,7,1);
	}
break;

beginstate 18; //Coffin Room
	if(get_flag(7,8) == 0) {
		message_dialog("You enter this spartan room, and immediately shudder. Despite its bareness, you are instantly aware of it's purpose - the wooden coffin lying at the opposite end of the room isn't just for decoration.","This must be Tovas's crypt. Strangely though, the room is dusty - nobody has been in here in a while...");	
		message_dialog("You look closer at the pictures that adorn the walls on either side of the coffin, and realise they are of the same person; a young lady with fiery red-hair and piercing green eyes.","However, they are faded beyond belief - they are clearly terribly old. They must be special somehow."); 
		if(get_flag(7,15) == 1) {
			message_dialog("Looking again, you're sure that these paintings are of the same girl you saw in other paintings in the tower - it's the same red hair, and the same green eyes...","You wonder who she was.");
		}
		set_flag(7,8,1);
	}
break;

beginstate 19; //Coffin room boxes
	message_dialog("You greedily throw open this box, expecting to find the hordes of wealth all vampires are reputed to have gathered in their endless lives. You are sorely disappointed... It's empty.","");
break;	

beginstate 20; //Garden door
	if(get_flag(7,10) == 0) {
		reset_dialog();
		add_dialog_str(0,"You open this door and enter a small, walled-off garden. This is by far the most beautiful place in the tower. In fact, it could almost be a description from a fairy story.",0);
		add_dialog_str(1,"The grass is lush and verdant underfoot, the lilacs bloom majestically, and the tall trees around you soar upwards with idle grace. It is the ceiling, though, that truly stuns you...",0);
		add_dialog_str(2,"The ceiling of this garden has been enchanted to show the night sky - it is almost as if you were outside. The moon, you can't be sure if it's real or not, is waxing before your eyes, and the fiery glow of Venus is visible.",0);
		add_dialog_str(3,"Reluctantly you pull yourself away from the heavens. You have a job to do...",0);
		run_dialog(1);
		set_flag(7,10,1);
	}
break;

beginstate 21;	//Altar 
	message_dialog("This altar is just a huge slab of rock that has been smoothed down. It has no magical properties whatsoever - it must just be a focusing object and not a shrine.","");
break;

beginstate 22; //Deer Statue in stoneworks
	if(get_flag(7,11) == 0) {
		message_dialog("You take a closer look at this statue. Even in it's unfinished state, you can clearly see what it is meant to be, and can also recognise that it is being carved by the same hand that made all of the statues in the tower.","You reach out, and run your hand along it, childishly half-expecting it to move as you do. It is so smooth, so *perfect*, that it could almost be the real thing.");
		set_flag(7,11,1);
	} else {
		print_str("You look at the statue again.");
	}
break;

beginstate 23; //Stoneworks door
	if(get_flag(7,12) == 0) {
		message_dialog("You enter this small room, and are assaulted by dust and small bits of stone. They cling to your clothes and hair, disturbed as they were by the sudden draft of air you created as you entered.","The room appears to be some kind of workshop - hammers and scalpels litter the floor, and huge chunks of rock are everywhere. You hold your breath as you enter - the air is thick with dust.");
		set_flag(7,12,1);
	}
break;

beginstate 24; //Antler's (oh, a puzzle *yawn*)
	if(get_flag(7,13) == 0) {
		reset_dialog();
		add_dialog_str(0,"You look at this deer's head closely. It isn't actually a stuffed creature, but instead a sculpture of one. You run your hands over it, admiring the handiwork, and notice that the left antler seems to be on a pivot. Pull it?",0);
		add_dialog_choice(0,"Yes, pull it.");
		add_dialog_choice(1,"No, leave it.");
		if(run_dialog(1) == 2) {
			message_dialog("Staying on the side of caution, you leave it alone.","");
			end();
		} else {
			message_dialog("You pull the antler towards you, and let go. It slowly rights itself to its former position. There is no indication that anything happened.","");
			set_flag(7,13,1);
			flip_terrain(23,8);
		}
	} else {
		print_str("There is nothing else you can do here.");
	}
break;

beginstate 25; //Door to P
	if(get_flag(7,13) == 1) {
		end();
		} 
	if(get_flag(7,14) == 1) {
		end();
	} else {
		message_dialog("You approach this door, and stop, puzzled. You have to blink twice, to make sure you didn't miss it - the door has no handle. Shrugging, you push against it, thinking it'll just give way. No such luck.","In fact, there doesn't seem to be any visible way to get into the room beyond. Maybe there's a hidden switch nearby, or something...");
		set_flag(7,14,1);
	}
	
break;

beginstate 26; //P room
	if(get_flag(7,15) == 0) {
		reset_dialog();
		add_dialog_str(0,"You walk across this small crypt, heading towards the coffin at the other end. Suddenly though, your legs stop working. You take a step backwards, and try again. No cigar.",0);
		add_dialog_str(1,"There appears to be some kind of ward stopping you from progressing, so you look around. The room is probably the nicest you've seen so far, which is saying something considering where you are.",0);
		add_dialog_str(2,"What really catches your eye though, are the two portraits either side of the coffin. Presumably they are of the deceased, although you aren't close enough to the casket to be able check.",0);
		add_dialog_str(3,"The pictures are of a young-ish woman, with wavy red hair that glistens in the low sunlight. Her eyes are a piercing green, and they seem to be staring right into your very soul.",0);
		add_dialog_str(4,"You pull your eyes away, although it pains you to turn from something so beautiful. As you do, you hear a single word in your head, echoed a thousand times... _Soon._ You shake your head, and move on.",0);
		run_dialog(1);
		set_flag(7,15,1);
		block_entry(1);
	} else {
		print_str("You still can't move any further west.");
		block_entry(1);
	}
break;

beginstate 27; //Painting room
	if(get_flag(7,16) == 0) {
		message_dialog("You enter this room, and immediately wonder what its for. It is completely devoid of features, apart from 4 tall pillars, stretching upwards, and 3 paintings on the far wall.","The pictures are heavy with dust, as is everything else in here. Tovas must not frequent this room very often.");
		set_flag(7,16,1);
	} 
break;

beginstate 28; //Left painting
	if(get_flag(7,17) == 0) {
		message_dialog("You carefully wipe away some of the dust covering the picture, in order to see what it is. After a while, a picture is visible underneath the remaining dirt.","You step back and look, and see a fairly plain painting of what looks like the Vale. Everything looks very drab, although you aren't sure if that's the dust, or the style of painting.");
		set_flag(7,17,1);
	} else {
		print_str("You look at the picture again.");
	}
break;

beginstate 29; //Centre painting
	if(get_flag(7,18) == 0) {
		message_dialog("You carefully wipe away some of the dust covering the picture, in order to see what it is. After a while, a picture is visible underneath the remaining dirt.","You step back and look, and see a fairly plain painting of a young man in armour. Everything looks very drab, although you aren't sure if that's the dust, or the style of painting.");
		set_flag(7,18,1);
	} else {
		print_str("You look at the picture again.");
	}
break;

beginstate 30; //Right painting
	if(get_flag(7,19) == 0) {
		message_dialog("You carefully wipe away some of the dust covering the picture, in order to see what it is. After a while, a picture is visible underneath the remaining dirt.","You step back and look, and see a fairly plain painting of some lilies. Everything looks very drab, although you aren't sure if that's the dust, or the style of painting.");
		set_flag(7,19,1);
	} else {
		print_str("You look at the picture again.");
	}
break;

beginstate 36; //Apothecary greeting
	if(get_flag(7,20) == 0) {
		message_dialog("You enter this foul-smelling room, and immediately see its purpose - it is an apothecary of some description. Two cauldrons sit bubbling nearby -  somebody has been in here recently, although you can't tell why.","");
		set_flag(7,20,1);
	}
break;

beginstate 37; //Insta-kill cauldrons
	reset_dialog();
	add_dialog_str(0,"The liquid in this cauldron is bubbling fiercely as you approach, and the fumes it is kicking off are less than pleasant - you feel woozy just standing near them.",0);
	add_dialog_str(1,"There is a ladle inside, and you're sure nobody would know if you had a sip. However, the contents might be particularly dangerous. You have no idea what's being made here. Do you try some?",0);
	add_dialog_choice(0,"Yes, have a sip.");
	add_dialog_choice(1,"No, leave it alone.");
	if(run_dialog(1) == 1) {
		message_dialog("You pull put the ladle, and take a sip. Unfortunately, the liquid being brewed was either deliberately poisonous, or else it's not quite had long enough to turn safe yet.","You quickly pass out. You never wake up...");
		kill_char(1000,2,0);
	} else {
		end();
	}
break;

beginstate 31; //Rotting store
	if(get_flag(7,21) == 0) {
		message_dialog("This room is filthy. It appears as though everything and anything has been thrown in here, and given about 20 years to gather dust.","Looking round, there doesn't seem to be anything of value in here, but you'd have to give up a whole week to check for sure.");
		set_flag(7,21,1);
	}
break;

beginstate 32; //Central Hall
	if(get_flag(7,23) == 0) {
		message_dialog("You step into this central hall, and freeze. Standing guard at the doors opposite are a pair of ghosts. You finger your weapons, not entirely sure whether or not they'll have an effect or pass right through the beings.","Then, one of them shakes its head, and begins speaking...");
			set_flag(7,23,1); //Set this now, so I don't forget later.	
			
			//Prep for short cutscene
			force_view_center(28,24);
			force_instant_terrain_redraw();
			
			//Now for the fun...
			text_bubble_on_char(7,"They won't work...");
			force_instant_terrain_redraw();
			pause(10);
			
			text_bubble_on_char(7,"");
			force_instant_terrain_redraw();
				
			text_bubble_on_char(6,"...so put them away.");
			force_instant_terrain_redraw();
			pause(10);
			
			text_bubble_on_char(6,"");
			force_instant_terrain_redraw();
			
			message_dialog("You pause, and frown. _Your weapons... You were wondering whether or not they'd hurt us. They wouldn't. Oh, and yes, we do know where the Master is._","The 'Master'? It must mean Tovas...");
			
			text_bubble_on_char(7,"Yes, we mean Tovas.");
			force_instant_terrain_redraw();
			pause(10);
			
			text_bubble_on_char(7,"");
			force_instant_terrain_redraw();

			text_bubble_on_char(6,"And we don't like being called 'it'.");
			force_instant_terrain_redraw();
			pause(10);
			
			text_bubble_on_char(6,"");
			force_instant_terrain_redraw();
			
			text_bubble_on_char(7,"Anyway, He's waiting.");
			force_instant_terrain_redraw();
			pause(12);
			
			text_bubble_on_char(7,"");
			text_bubble_on_char(6,"So go.");
			force_instant_terrain_redraw();
			pause(10);
			
			message_dialog("And with that, they clam up. Weird. They must have some kind of telepathic skill... And they also said Tovas was waiting for you. You dearly hope he will be as accommodating as he was before.","");
			
			force_view_center(31,24);
			text_bubble_on_char(6,"");
			force_instant_terrain_redraw();
		}
break;

beginstate 33; //Story of shades being trapped
	reset_dialog();
	add_dialog_str(0,"_We are here because we cannot leave. It was a long story, but much has been forgotten in the centuries since it happened. I will, however, do my best to explain._",0);
	add_dialog_str(1,"_Once, in the distant past, the spirits trapped in this tower lived in the Valley below. At that time, the tower was still connected to the land. The chasm to the south came much, much later. Anyway,_ it pauses _I digress..._",0);
	add_dialog_str(2,"_We were adventurers, on a mission to rescue a princess from the Master of the Tower, a mage named _Lord Monkton_. We managed to penetrate the gates, and stormed the place, but he was lying in wait for us._",0);
	add_dialog_str(3,"_He smote us down, and cursed us. Our punishment for trying to kill him was to spend eternity serving the master of the Tower, whomsoever it should be. Years passed, and Lord Monkton died. The Tower fell to ruin. And still we waited, unable to leave._",0);
	add_dialog_str(4,"_Then, a young woman came - Alexandra. She moved in, and it was she who destroyed the Earth to the south, to separate the Tower from the Vale. But her tale is another story..._",0);
	run_dialog(1);
break;

beginstate 34; //How many masters question
	reset_dialog();
	add_dialog_str(0,"_We do not remember all of the masters - much has been forgotten. There was Lord Monkton first, though. We remember him. It was he who trapped us, and who eventually died. We did not mourn his passing - we still remembered what hate was then._",0);
	add_dialog_str(1,"_Then, after he went, the Tower grew dark and desolate. Nobody came for years. And then Mistress Alexandra came, and unlocked the Tower, and moved in. She was the first dead person we had met, and she helped us come to terms with our death._",0);
	add_dialog_str(2,"The ghost sees you frown and explains. _Alexandra was a vampire, such as Tovas. It was she who sired Tovas's patron. We forget who he was - this, of course, was centuries before Tovas was even born, and he is over two hundred years old._",0);
	add_dialog_str(3,"_Alexandra left, and we do not know where she went. Her vampiric child stayed behind. Those were dark years, and we forgot most of them willingly. We do remember, though, Tovas's first visit to the Tower._",0);
	add_dialog_str(4,"_But the story of our current Master is one for another time._",0);
	run_dialog(1);
break;

beginstate 35; //Basic Tovas history
	reset_dialog();
	add_dialog_str(0,"_Tovas is our Master at the minute. You should speak to him about the present - we do not know much about that..._",0);
	add_dialog_str(1,"_But of the past, we know lots. Some of which we have been told not to share, and we won't, but we were told to answer any questions you may have, and we WILL do that._",0);
	add_dialog_str(2,"_Tovas first came to the Tower ages ago, with his friend Pandora. They stayed here, at the tower, and he eventually became as he is now. We do not know how, exactly, and the Master is loathe to say._",0);
	add_dialog_str(3,"_As for Pandora, we do not know what happened to her either, but we do know she has a coffin to the north. We do not go there though, the place scares us, even now._",0);
	add_dialog_str(4,"_Tovas slew the vampire which sired him, although again, we do not know why. Much is lost to time... Since then, he has spent his years here, alone. And that is all that you can know right now._",0);
	run_dialog(1);
	set_flag(7,25,1);
break;

//His door, and the final movie
beginstate 38;
	//Alright, last stretch...
	
		set_flag(250,6,1);
	
	message_dialog("As you enter this room, you find Tovas and Laurina. She is in his arms, standing in the middle of the floor. She looks as if she has been crying... As you look closer, you realise they are discussing something...","");
	
	activate_hidden_group(1);
	set_character_pose(11,14);
	force_instant_terrain_redraw();

	force_view_center(18,34);
	
	force_instant_terrain_redraw();
	
	pause(2 * get_flag(250,5));
	
	//11 is tov 12 is lau
	
	text_bubble_on_char(11,"They are here."); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();

	pause(8 * get_flag(250,5));
	
	text_bubble_on_char(11,"We're decided?"); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	message_dialog("You hear Laurina mutter something, although you can't make out what. They embrace for a moment, and kiss. Then, she turns to stand next to him, and they look over to you. They knew you were there all along. _Come in,_ Tovas calls to you.","You, half unconsciously, obey.");
	
	set_character_pose(11,13);
	force_instant_terrain_redraw();
	
	march_party(18,31);
	pause(3 * get_flag(250,5));
	force_instant_terrain_redraw();
	
	march_party(19,32);
	pause(3 * get_flag(250,5));
	force_instant_terrain_redraw();
	
	march_party(19,33);
	pause(3 * get_flag(250,5));
	force_instant_terrain_redraw();
	
	march_party(19,34);
	pause(3 * get_flag(250,5));
	force_instant_terrain_redraw();
	
	march_party(19,35);
	pause(3 * get_flag(250,5));
	set_character_facing(1000,2);
	force_instant_terrain_redraw();
	
	pause(2);
	
	message_dialog("Tovas looks across at you. Then he bows his head. _Well, you have found me, again, adventurers. And I did warn you what would happen if you did. However..._ he begins.","");
	
	text_bubble_on_char(11,"...I am tired of running."); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	text_bubble_on_char(11,"Me and Laurina have spoken..."); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	text_bubble_on_char(11,"...and our love cannot be."); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	text_bubble_on_char(11,"Stone can have her back."); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	text_bubble_on_char(11,"But warn him it won't be for ever."); 
	force_instant_terrain_redraw();
	pause(6 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	message_dialog("Laurina steps away from Tovas, and turns to him...","");
	
	activate_hidden_group(2);
	set_character_pose(11,0);
	force_instant_terrain_redraw();
	
	text_bubble_on_char(12,"And you promise?"); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	text_bubble_on_char(11,"Of course. Now, go."); 
	force_instant_terrain_redraw();
	pause(5 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	message_dialog("They lean in close for a kiss, whilst you watch, wondering what all this is. Then, suddenly, Tovas waves his hand and he disappears!","Have you really managed to escape without having to fight, or talk, or do ANYTHING?");
	
	put_boom_on_char(11,3,0);
	run_animation_sound(-10);
	erase_char(11);
	force_instant_terrain_redraw();
	
	reset_dialog();
	add_dialog_str(0,"Laurina turns to you, and wipes her eyes. _Well, that's that, I guess. Will you take me back to Greenleaf?",0);
	run_dialog(1);
	
	text_bubble_on_char(0,"Yes, come on."); 
	force_instant_terrain_redraw();
	pause(4 * get_flag(250,5));
			
	erase_text_bubbles();
	force_instant_terrain_redraw();
	
	add_char_to_party(12);
	
	message_dialog("You take her by the arm, and prepare to leave. As you wander through the craven halls of Tovas's lair, Laurina lingers and looks about. Her heart seems heavy, and she doesn't say anything.","Eventually, you arrive back at the teleportal platform...");
	
	move_to_new_town(3,6,12);
break;
	